Lentz's algorithm